import axios from 'axios'
import store from '@/store'
// import Vue from 'vue'

// 创建实例
const request = axios.create({
  baseURL: 'http://127.0.0.1:7001'
})

// 添加请求拦截器
request.interceptors.request.use(function (config) {
  config.headers = {
    'Content-Type': 'application/json'
  }

  const { state } = store
  if (state.token) {
    config.headers.Authorization = `Bearer ${state.token}`
  }

  return config
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error)
})

export default request
